#include "../mq_server/mq_message.hpp"
#include <gtest/gtest.h>

using namespace mq_server;

// MessageManager::ptr mmp;

// class MessageTest  : public testing::Environment {
//     public:
//         virtual void SetUp() override {
//             mmp = std::make_shared<MessageManager>("./data/message/");
//             mmp->InitQueueMessage("queue1");
//         }
//         virtual void TearDown() override {
//             // mmp->Clear();
//         }
// };

//新增消息测试：新增消息，然后观察可获取消息数量，以及持久化消息数量
// TEST(message_test, insert_test) {
//     BasicProperties properties;
//     properties.set_id(UUIDHelper::UUID());
//     properties.set_delivery_mode(DeliveryMode::DURABLE);
//     properties.set_routing_key("news.music.pop");
//     mmp->Insert("queue1", &properties, "Hello World-1", DeliveryMode::DURABLE);
//     mmp->Insert("queue1", nullptr, "Hello World-2", DeliveryMode::DURABLE);
//     mmp->Insert("queue1", nullptr, "Hello World-3", DeliveryMode::DURABLE);
//     mmp->Insert("queue1", nullptr, "Hello World-4", DeliveryMode::DURABLE);
//     mmp->Insert("queue1", nullptr, "Hello World-5", DeliveryMode::UNDURABLE);
//     ASSERT_EQ(mmp->Getable_Count("queue1"), 5);
//     ASSERT_EQ(mmp->Total_Count("queue1"), 4);
//     ASSERT_EQ(mmp->Durable_Count("queue1"), 4);
//     ASSERT_EQ(mmp->Waitack_Count("queue1"), 0);
// }

//恢复历史数据测试

MessageManager::ptr mmp1;
class MessageTest2 : public testing::Environment {
    public:
        virtual void SetUp() override {
            mmp1 = std::make_shared<MessageManager>("./data/message/");
        }
        virtual void TearDown() override {
            //mmp->clear();
        }
};
TEST(message_test2, recovery_test) {
    mmp1->InitQueueMessage("queue1");
    ASSERT_EQ(mmp1->Getable_Count("queue1"), 4);
    // bitmq::MessagePtr msg1 = mmp1->front("queue1");
    // ASSERT_NE(msg1.get(), nullptr);
    // ASSERT_EQ(msg1->payload().body(), std::string("Hello World-1"));
    // ASSERT_EQ(mmp1->getable_count("queue1"), 3);
    // ASSERT_EQ(mmp1->waitack_count("queue1"), 1);

    // bitmq::MessagePtr msg2 = mmp1->front("queue1");
    // ASSERT_NE(msg2.get(), nullptr);
    // ASSERT_EQ(msg2->payload().body(), std::string("Hello World-2"));
    // ASSERT_EQ(mmp1->getable_count("queue1"), 2);
    // ASSERT_EQ(mmp1->waitack_count("queue1"), 2);

    // bitmq::MessagePtr msg3 = mmp1->front("queue1");
    // ASSERT_NE(msg3.get(), nullptr);
    // ASSERT_EQ(msg3->payload().body(), std::string("Hello World-3"));
    // ASSERT_EQ(mmp1->getable_count("queue1"), 1);
    // ASSERT_EQ(mmp1->waitack_count("queue1"), 3);

    // bitmq::MessagePtr msg4 = mmp1->front("queue1");
    // ASSERT_NE(msg4.get(), nullptr);
    // ASSERT_EQ(msg4->payload().body(), std::string("Hello World-4"));
    // ASSERT_EQ(mmp1->getable_count("queue1"), 0);
    // ASSERT_EQ(mmp1->waitack_count("queue1"), 4);
}

int main(int argc,char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MessageTest2);
    //testing::AddGlobalTestEnvironment(new MessageTest2);
    RUN_ALL_TESTS();
    return 0;
}